package com.example.demo.module;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

public class To_base64 {
    public String to_base64(String path){
        byte[] data = null;
        try (InputStream in = new FileInputStream(path)){
            data = new byte[in.available()];
            in.read(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 返回Base64编码过的字节数组字符串
        System.out.println("本地图片转换Base64: ");
        //System.out.println(Base64.getEncoder().encodeToString(data));
        String result=Base64.getEncoder().encodeToString(data);
        return result;
    }
}
